package dq.thread;

import java.util.concurrent.Executor;

/**
 * @Author: Dang Qi
 * @Date: 2021/3/17  13:49
 * @Description:
 */
public class A1B2{
    volatile static boolean flag = true;
    volatile static int i = 1;
    volatile static int ch = 0;
    public static void main(String[] args) {

        Thread t1 = new Thread(()->{
            while (true){
                while(!flag);
                System.out.println(Thread.currentThread().getName() + " " + i++);
                flag = !flag;
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
        Thread t2 = new Thread(()->{
            while (true){
                while(flag);
                System.out.println((Thread.currentThread().getName() + " " + ((char)(ch+'A'))));
                ch = (ch+1) % 26;
                flag = !flag;
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
        t1.start();
        t2.start();

    }

}
